<?

 /***********************************
 *  Pager class Powered by Rafia    *
 *                                  *
 *        www.rafiaphp.com          *
 *                                  *
 *        Pager version 3.0         *
 *//////////////////////////////////*

class Pager
{
    var $start;
    var $page;
    var $numrows;
    var $perpage;
    var $pagelink;
    var $addtext = 1;

    function Pager($_page, $_pagelink='')
    {
                if(!is_numeric($_page)){$_page=1;}
                $this->page      =  $_page;

                $this->pagelink  =  $_pagelink;
    }

    function SetPagerN($_perpage,$_numrows)
    {

        $this->perpage = $_perpage;
        $this->numrows = $_numrows;
    }

    function PageNum($page_var, $page_var_after="", $myphpself="")
    {
             global $info_row;

        if((isset($this->pagelink))&&($this->pagelink!=''))
        {
            $this->pagelink = $this->pagelink."&";
        }
                $this->pages = ceil($this->numrows/$this->perpage);
        if ($this->numrows>$this->perpage)
        {
            $pagenum = "";

            if($this->page == 0 OR $this->pages < $this->page)
            {
                $this->page = 1;
            }
            if($this->page > 0)
            {
                $this->page = $this->page - 1;
            }
            $this->maxpage =  $this->page + $info_row['page_max'] ;

			$pagem=$this->page+1;

            for ($i = $this->page ; $i <= $this->maxpage && $i <= $this->pages ; $i++)
            {
                if($i > 0)
                {

                    if ($i == $this->page+1)
                    {
                         $pagenum .= "<td class='row3dark'>$i</td>\n";
                    }
                    else
                    {
                            if (empty($myphpself)) {
                                 $pagenum .= "<td class='row3'><a href=$PHP_SELF?".$page_var.'&amp;'.$this->pagelink."page=$i" . $page_var_after . ">$i</a></td>\n";
                            }
                        else {
                                $pagenum .= "<td class='row3'><a href=" . $myphpself . "?".$page_var.'&amp;'.$this->pagelink."page=$i" . $page_var_after . ">$i</a><td>\n";
                        }
                    }
                }
            }
			

                        if ($this->addtext)
                        {
                                if (($this->page+1) != 1)
                                {
                                        $pagenum = '<td class="row3"><a href="' . $myphpself . '?' . $page_var . '&amp;'.$this->pagelink.'page=' . ($this->page) . '"><</a></td>' . $pagenum;
                                }

                                if(($this->page+1) > 5)
                                {
                                        if (empty($myphpself))
                                        {
                                                $pagenum =  "<td class='row3'><a href=$PHP_SELF?".$page_var.'&amp;'.$this->pagelink."page=1>الأولى</a></td> \n" . $pagenum;
                                        }
                                        else
                                        {
                                                $pagenum .=  "<td class='row3'><a href=" . $myphpself . "?".$page_var.'&amp;'.$this->pagelink."page=1>الأولى</a></td> \n";
                                        }
                                }

                                if (($this->page+1) != $this->pages)
                                {
                                        $pagenum .= '<td class="row3"><a href="' . $myphpself . '?' . $page_var . '&amp;'.$this->pagelink.'page=' . ($this->page + 2) . '">></a></td>';
                                }

                                if ($this->page+5 < $this->pages)
                                {
                                        $pagenum .= "<td class='row3'><a href=$PHP_SELF?".$page_var.'&amp;'.$this->pagelink."page=$this->pages>الاخيره</a></td>";
                                }
                        }
						$pagenum = '<table class="border"  style="margin:10px;" cellspacing="1"><tr><td class="thead">صفحة '.$pagem.' من '.$this->pages.'</td>'.$pagenum.'</tr></table>';
        }
        return $pagenum;
    }
	
	function PageNums($page_var, $page_var_after="", $myphpself="")
    {
             global $info_row;

        if((isset($this->pagelink))&&($this->pagelink!=''))
        {
            $this->pagelink = $this->pagelink."&";
        }
                $this->pages = ceil($this->numrows/$this->perpage);
        if ($this->numrows>$this->perpage)
        {
            $pagenum = "";

            if($this->page == 0 OR $this->pages < $this->page)
            {
                $this->page = 1;
            }
            if($this->page > 0)
            {
                $this->page = $this->page - 1;
            }
            $this->maxpage =  $this->page + $info_row['page_max'] ;
            for ($i = $this->page ; $i <= $this->maxpage && $i <= $this->pages ; $i++)
            {
                if($i > 0)
                {
                    if ($i == $this->page+1)
                    {
                         $pagenum .= "<b>$i</b>&nbsp;\n";
                    }
                    else
                    {
                            if (empty($myphpself)) {
                                 $pagenum .= "<a href=$PHP_SELF?".$page_var.'&amp;'.$this->pagelink."page=$i" . $page_var_after . ">$i</a>&nbsp;\n";
                            }
                        else {
                                $pagenum .= "<a href=" . $myphpself . "?".$page_var.'&amp;'.$this->pagelink."page=$i" . $page_var_after . ">$i</a>&nbsp;\n";
                        }
                    }
                }
            }

                        if ($this->addtext)
                        {
                                if ($this->page+5 < $this->pages)
                                {
                                        $pagenum .= ".... <a href=" . $myphpself . "?".$page_var.'&amp;'.$this->pagelink."page=$this->pages>الاخيره</a>";
                                }
                        }
        }
        return $pagenum;
    }
	
    function PageNum_source($page_var="",$page_var_after="")
    {
        if((isset($this->pagelink))&&($this->pagelink!=''))
        {
            $this->pagelink = $this->pagelink."&";
        }

        if ($this->numrows>$this->perpage)
        {
            if($this->page > 2)
            {

                $start=0;
                $page=1;
            }
            $this->pages = ceil($this->numrows/$this->perpage);
            if($this->page == 0)
            {
                $this->page = 1;
            }
            if($this->page > 0)
            {
                $this->page = $this->page - 1;
            }
            $this->maxpage =  $this->page + 100 ;
            for ($i = $this->page ; $i <= $this->maxpage && $i <= $this->pages ; $i++)
            {
                if($i > 0)
                {
                    $this->nextpag = $this->perpage*($i-1);
                    if ($this->nextpag == $this->start)
                    {
                         $pagenum .= "<p>$i</p>\n";
                    }
                    else
                    {
                         $start=$this->nextpag;
                         $page=$i;
                    }
                }
            }
            if (! ( ($this->start/$this->perpage) == ($this->pages - 1) ) && ($this->pages != 1) )
            {
                $this->nextpag = ($this->pages*$this->perpage)-$this->perpage;
                 //$pagenum .= " ... <a href=$PHP_SELF?".$this->pagelink."start=$this->nextpag&page=$this->pages>[$this->pages]</a>\n";
            }
             $pagenum .= "</p>";

        }
        return $start . "|" . $page;
    }
	
}
?>